/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yinshi.j2d;

import java.awt.Graphics2D;
import java.util.ArrayList;

/**
 *
 * @author yinshi
 */
public abstract class Group extends Node {

    private ArrayList<Node> nodes = new ArrayList<>();

    public Node get(int index) {
        return nodes.get(index);
    }

    public boolean add(Node e) {
        return nodes.add(e);
    }

    public Node[] getChildren() {
        return nodes.toArray(new Node[0]);
    }

    public void paint(Graphics2D g, int x, int y, int width, int height) {
        for (Node node : getChildren()) {
            node.paint(g, x, y, width, height);
        }
    }

    protected void paintNode(Graphics2D g, int x, int y, int width, int height) {
    }
}
